<script lang="ts" setup>
import { useRouter } from 'vue-router'

//通过porps来实现标题和右侧文字的传递
const props = defineProps<{
  title: string | undefined
  rightText: string | undefined
  back: () => void | undefined
}>()
//使用emits来实现左侧箭头的点击事件
const emit = defineEmits<{
  (e: 'click-right'): void
}>()
const onclickRight = () => {
  emit('click-right')
}
//回退
const router = useRouter()
const onclickLeft = () => {
  if (props.back) return props.back()
  if (history.state.back) {
    router.back()
  } else {
    router.push('/')
  }
}
</script>

<template>
  <!-- 固定定位 -->
  <van-nav-bar
    fixed
    left-arrow
    @click-left="onclickLeft"
    :title="title"
    :right-text="rightText"
    @click-right="onclickRight"
  />
</template>

<style lang="scss" scoped>
:deep() {
  .van-nav-bar {
    &__arrow {
      color: var(--cp-text);
      font-size: 18px;
    }
    &__title {
      font-size: 15px;
    }
  }
}
</style>
